﻿@using CollegeShop.WebProcessor
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>@ViewBag.Title</title>
    <meta name="description" content="@ViewBag.Description" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link href="/Content/themes/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!--[if lte IE 6]>
       <link rel="stylesheet" type="text/css" href="/Content/themes/bootstrap-ie/css/bootstrap-ie6.css" />
       <link rel="stylesheet" type="text/css" href="/Content/themes/bootstrap-ie/css/ie.css" />
    <![endif]-->
    <link href="/Content/themes/font-awesome/css/font-awesome.min.css" rel="stylesheet"
        type="text/css" />
    <!--[if IE 7]>
    <link href="/Content/themes/font-awesome/css/font-awesome-ie7.min.css" rel="stylesheet"
        type="text/css" />
    <![endif]-->
    <link href="/Content/custom.css" rel="stylesheet" type="text/css" />
    <link href="/Content/ace.min.css" rel="stylesheet" type="text/css" />
    <!--[if lte IE 8]>
	    <link rel="stylesheet" type="text/css"  href="/Content/ace-ie.min.css" />
	<![endif]-->
    <!--[if lt IE 9]>
		<script rel="stylesheet" type="text/css" src="/scripts/html5shiv.js"></script>
		<script rel="stylesheet" type="text/css" src="/scripts/respond.min.js"></script>
	<![endif]-->
    <link href="/Content/custom.css" rel="stylesheet" type="text/css" />
    @RenderSection("head", false)
</head>
<body>
    <div class="navbar navbar-default">
        <div class="navbar-container">
            <div class="pull-left" style="padding-top: 5px;">
                <a href="/" style="text-decoration: none;" class="navbar-brand"><i class="icon-magic icon-white">
                </i>校园速购 </a>
            </div>
            <div class="pull-right">
                <ul class="nav ace-nav">
                    <li class="purple"><a style="padding: 0 10px 0;" data-toggle="dropdown" class="dropdown-toggle"
                        href="javascript:;"><i class="icon-lemon"></i></a>
                        <ul class="pull-right dropdown-navbar navbar-pink dropdown-menu dropdown-caret dropdown-close">
                            <li class="dropdown-header"><i class="icon-retweet"></i>我们为您准备了最热门的商品 </li>
                            <li><a @(HttpContext.Current.Request.RawUrl.Equals("/") || HttpContext.Current.Request.RawUrl.Equals("/home/index") ? "" : "  target=_blank") href="@(HttpContext.Current.Request.RawUrl.Equals("/") || HttpContext.Current.Request.RawUrl.Equals("/home/index") ? "#snacks" : "/#snacks")">
                                <div class="clearfix">
                                    <span class="pull-left"><i class="btn btn-xs no-hover btn-pink icon-heart"></i>时尚小吃
                                    </span>
                                </div>
                            </a></li>
                            <li><a @(HttpContext.Current.Request.RawUrl.Equals("/") || HttpContext.Current.Request.RawUrl.Equals("/home/index") ? "" : "  target=_blank") href="@(HttpContext.Current.Request.RawUrl.Equals("/") || HttpContext.Current.Request.RawUrl.Equals("/home/index") ? "#cake" : "/#cake")">
                                <div class="clearfix">
                                    <span class="pull-left"><i class="btn btn-xs btn-primary icon-coffee"></i>充饥必备
                                    </span>
                                </div>
                                 
                            </a></li>
                            <li><a @(HttpContext.Current.Request.RawUrl.Equals("/") || HttpContext.Current.Request.RawUrl.Equals("/home/index") ? "" : "  target=_blank") href="@(HttpContext.Current.Request.RawUrl.Equals("/") || HttpContext.Current.Request.RawUrl.Equals("/home/index") ? "#drink" : "/#drink")">
                                <div class="clearfix">
                                    <span class="pull-left"><i class="btn btn-xs no-hover btn-success icon-beer"></i>营养饮品
                                    </span>
                                </div>
                            </a></li>
                            <li><a @(HttpContext.Current.Request.RawUrl.Equals("/") || HttpContext.Current.Request.RawUrl.Equals("/home/index") ? "" : "  target=_blank") href="@(HttpContext.Current.Request.RawUrl.Equals("/") || HttpContext.Current.Request.RawUrl.Equals("/home/index") ? "#other" : "/#other")">
                                <div class="clearfix">
                                    <span class="pull-left"><i class="btn btn-xs no-hover btn-info icon-music"></i>其他
                                    </span>
                                </div>
                            </a></li>
                            @*<li><a href="#">
                                <div class="clearfix">
                                    <span class="pull-left"><i class="btn btn-xs no-hover btn-danger icon-edit"></i>您还想购买什么？
                                    </span>
                                </div>
                            </a></li>*@
                            <li><a href="#">
                                <div class="clearfix">
                                    <span class="pull-left"><i class="btn btn-xs no-hover btn-warning icon-android"></i>
                                        下载安卓应用 </span>
                                </div>
                            </a></li>
                        </ul>
                    </li>
                    @{
                        //购物车设置
                        List<CollegeShop.Infrastructure.Entities.Entity.Goods> list = new List<CollegeShop.Infrastructure.Entities.Entity.Goods>();
                        var cookie = Request.Cookies["goodscart"];
                        if (cookie != null && !String.IsNullOrEmpty(cookie.Value))
                        {
                            List<string> idList = Server.UrlDecode(cookie.Value).Split(',').ToList().Distinct().ToList();
                            if (idList.Any())
                            {
                                foreach (var item in idList)
                                {
                                    if (!String.IsNullOrEmpty(item))
                                    {
                                        int id = -1;
                                        if (Int32.TryParse(item, out id))
                                        {
                                            var commodity = CollegeShop.Biz.CommodityBiz.LoadCommodity(id);
                                            if (commodity != null)
                                            {
                                                list.Add(commodity);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    <li class="grey"><a style="padding: 0 10px 0;" data-toggle="dropdown" class="dropdown-toggle"
                        href="#"><i class="icon-shopping-cart @((list != null && list.Any()) ? "icon-animated-bell" : "")">
                        </i></a>
                        <ul id="cartbox" class="innerclick pull-right dropdown-navbar dropdown-menu dropdown-caret dropdown-close">
                            <li class="dropdown-header"><i class="icon-shopping-cart"></i>已选择 <span id="cmdcount">@list.Count</span>
                                件商品 </li>
                            @{
                                if (list != null && list.Any())
                                {
                                    foreach (var item in list)
                                    {
                                <li><a href="javascript:;">
                                    <img alt="@item.GoodsTitel" src="@item.Resource.Path" class="msg-photo" />
                                    <span class="msg-body"><span class="msg-title">
                                        @item.GoodsTitel
                                    </span><span class="msg-time"><i class="icon-angle-right"></i>&nbsp; <span class="red bolder">@item.DefaultSalePrice.ToString("F2")
                                        元</span> </span></span></a></li>
                                    }
                                }
                                else
                                {
                                <li class="noncommodity"><a href="javascript:;">
                                    <div style="text-align: center;">
                                        您还没有选择任何商品
                                    </div>
                                </a></li>
                                }
                            }
                            <li>
                                <div style="padding: 5px;" class="pull-right">
                                    <a id="cartboxtocart" href="@((list != null && list.Any()) ? "/home/cart" : "javascript:;")" class="btn btn-warning btn-mini">
                                        确认订单</a>
                                </div>
                            </li>
                        </ul>
                    </li>
                    <li class="green">
                        @{
                            //热门商品
                            List<CollegeShop.Infrastructure.Entities.Entity.Goods> popular = CollegeShop.Biz.CommodityBiz.LoadPopular(5);
                        }
                        <a style="padding: 0 10px 0;" data-toggle="dropdown" class="dropdown-toggle" href="#">
                            <i class="icon-tasks"></i></a>
                        <ul class="innerclick pull-right dropdown-navbar dropdown-menu dropdown-caret dropdown-close">
                            <li class="dropdown-header"><i class="icon-envelope-alt"></i>热门商品 </li>
                            @if (popular != null && popular.Any())
                            {
                                foreach (var item in popular)
                                {
                                <li>
                                <a href="#">
                                    <img src="@item.Resource.Path" alt="@item.GoodsTitel" class="msg-photo"/>
                                    <span class="msg-body">
                                        <span class="msg-title">@item.GoodsName</span>
                                        <span class="msg-time">
                                            <input type="button" commodity-id="@item.ID" commodity-price="@item.DefaultSalePrice" data-placement="top" 
                                                data-content="已添加至购物车" 
                                                data-html="false" data-trigger="click" class="populartocart btn btn-primary btn-minier" value="加入购物车" />
                                            <input type="button" class="popularbuy btn btn-warning btn-minier" value="立即购买" />
                                        </span>
                                    </span>
                                </a>
                                </li>
                                }
                            }
                            <li></li>
                        </ul>
                    </li>
                    <li class="light-blue">
                        @if (HttpContext.Current.User.Identity.IsAuthenticated)
                        {
                            <a style="padding: 0 10px 0;" data-toggle="dropdown" href="#" class="dropdown-toggle">
                                <i class="icon-user icon-2x"></i><span class="user-info">@(PageProcessor.CurrentUser() == "Local" ? "本机登陆" : PageProcessor.CurrentUser())
                                </span><i class="icon-caret-down"></i></a>
                            <ul class="user-menu pull-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close">
                                <li><a href="/order/list"><i class="icon-reorder"></i>我的订单 </a></li>
                                <li class="divider"></li>
                                <li><a href="/account/signout"><i class="icon-signout"></i>退出 </a></li>
                            </ul>
                        }
                        else
                        {
                            <a style="padding: 0 10px 0;" data-toggle="dropdown" href="#" class="dropdown-toggle">
                                <i class="icon-user icon-2x"></i><span class="user-info"><small>未登陆</small> </span>
                                <i class="icon-caret-down"></i></a>
                            <ul class="user-menu pull-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close">
                                <li><a href="/account/signin"><i class="icon-signin"></i>登陆 </a></li>
                                <li><a href="/account/register"><i class="icon-user"></i>注册 </a></li>
                            </ul>
                        }
                    </li>
                </ul>
            </div>
        </div>
    </div>
    @RenderBody()
    <footer>
        <div class="row footer" style="background-color:#e4e6e9;">
                <div class="foot-title">校园速购</div>
                <div class="foot-content">重庆xxx科技有限责任公司 版权所有 &copy; Copyright 2013 渝ICP备 xxxxxxx</div>
        </div>
    </footer>
    <script src="/Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script src="/Content/themes/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <!--[if lte IE 6]>>
  <script type="text/javascript" src="/Content/themes/bootstrap-ie/js/bootstrap-ie.js"></script>
  <![endif]-->
    <script type="text/javascript" src="/scripts/library.js"></script>
    <script type="text/javascript">
        $(function () {
            $('.innerclick').click(function (e) {
                e.stopPropagation();
            });
            if (!navigator.cookieEnabled) {
                alert('您禁用了cookie，会导致您无法使用本系统。请开启cookie');
            }
            $('.popularbuy').each(function () {
                $(this).click(function () {
                    $(this).siblings('input').trigger('click');
                    window.location.href = '/home/cart';
                    if ($.browser.msie && $.browser.version == 6) {
                        window.event.returnValue = false;
                    }
                });
            });
            $('.populartocart').each(function () {
                $(this).popover();
                $(this).click(function (e) {
                    var commodityId = $(this).attr('commodity-id');

                    var cart = getCookie('goodscart');
                    if (!ishas(unescape(cart).split(','), commodityId)) {
                        var count = 0;
                        if (!cart) {
                            setCookie('goodscart', commodityId + ',');
                            count = 1;
                        }
                        else {
                            var goods = cart.split(',');
                            goods.push(commodityId);
                            goods = distinct(goods);
                            count = goods.length;
                            cart = goods.join();
                            setCookie('goodscart', cart);
                        }
                        $('#cmdcount').text(count);
                        if ($('.noncommodity').length > 0) {
                            $('.noncommodity').remove();
                        }

                        var img = $(this).parent().parent().siblings('img');
                        var title = img.attr('alt');
                        $('#cartbox').children('li.dropdown-header').after(
                        $('<li />').append(
                            $('<a href="javascript:;" />').append(
                                $('<img alt="' + img.attr('alt') + '" src="' + img.attr('src') + '" class="msg-photo" />')
                            ).append(
                                $('<span class="msg-body" />').append(
                                    $('<span class="msg-title">' + title + '</span>')
                                ).append(
                                    $('<span class="msg-time" />').append(
                                        $('<i class="icon-angle-right"></i>&nbsp;')
                                    ).append(
                                        $('<span class="red bolder">' + $(this).attr('commodity-price') + '</span>')
                                    )
                                )
                            ))
                        );
                    }
                });
            });
            $('body').click(function () {
                if ($('.popover-content').length != 0) {
                    $('.populartocart').popover('hide');
                }
            });
        });
    </script>
    @RenderSection("tail", false)
</body>
</html>
